package com.ys.peony.ui.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.squareup.picasso.MemoryPolicy;
import com.squareup.picasso.Picasso;
import com.ys.peony.R;
import com.ys.peony.app.BaseApplication;
import com.ys.peony.ui.widget.imagecheckdialog.TouchImageView;

import java.io.File;

/**
 * 自定义
 */
public class PicShowDialog {

    /**
     * 应用上下文
     **/
    private Context context;

    /**
     * 回调接口
     **/
    private CustomAlertDialogCallBack callback;

    /**
     * 标题视图
     **/
    private TextView titleView;
    private TouchImageView img;

    private Dialog dialog;

    /**
     * 重载的构造方法
     *
     * @param context
     * @param callback
     */
    public PicShowDialog(Context context, CustomAlertDialogCallBack callback) {
        this(context, callback, -1);
    }

    public PicShowDialog(Context context, CustomAlertDialogCallBack callback, int windowType) {
        // 1.接受上下文对象
        this.context = context;

        // 2.接受回调
        this.callback = callback;

        // 3.生成窗体
        dialog = new Dialog(this.context, R.style.mypicdialog);
        // 4.初始化视图
        initUIView();
        dialog.show();
    }

    /**
     * 初始化窗口视图
     */
    private void initUIView() {
        LayoutInflater factory=LayoutInflater.from(this.context);
        View view=factory.inflate(R.layout.pop_pic_show, null);
        img=(TouchImageView)view.findViewById(R.id.pic_img);
        img.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if(callback!=null){
                    callback.onSureBtnClicked();
                }
                dismiss();
                return true;
            }
        });
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        //显示修改密码布局文件
        dialog.setContentView(view);

    }


    /**
     * 构造方法
     *
     * @param context
     */
    public PicShowDialog(Context context) {
        this(context, null);
    }

    public void setImgPath(String path) {
        if(img!=null){
            Picasso.with(context).load(path)
                    .error(R.mipmap.pic_load_error)
                    .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
                    .into(img);
        }

    }

    /**
     * 设置按钮
     *
     * @param text
     */
    public void setPositiveButton(String text) {

    }

    /**
     * 设置按钮
     *
     * @param text
     */
    public void setNegativeButton(String text) {
    }

    /**
     * 关闭对话框
     */
    public void dismiss() {
        dialog.dismiss();
    }

    /*
     * 获取当前dialog
     */
    public Dialog getDialog() {
        return this.dialog;
    }
}
